package com.bss.model;

// Generated Oct 27, 2011 10:37:49 PM by Hibernate Tools 3.3.0.GA

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "Receipt")
public class Receipt extends com.andy.basics.AbstractEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3174582443077674227L;

	private int id;

	private String remarks;

	private List<Payment> payments = new ArrayList<Payment>(0);

	@Id
	@Column(name = "id", unique = true, nullable = false)
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Integer getId() {
		return this.id;
	}

	@Override
	public void setId(final int id) {
		this.id = id;
	}

	public void setPayments(final List<Payment> payments) {
		this.payments = payments;
	}

	@OneToMany(fetch = FetchType.EAGER, mappedBy = "receipt", cascade = CascadeType.PERSIST)
	public List<Payment> getPayments() {
		return this.payments;
	}

	public Date getDate() {
		return super.date;
	}

	@Override
	public String toString() {
		StringBuilder receiptText = new StringBuilder();
		for (Payment payment : this.getPayments()) {
			receiptText.append(payment.getPaymentType().getName());
			receiptText.append("-");
			receiptText.append(payment.getAmount());
			receiptText.append(", ");
		}
		return receiptText.toString();
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	public String getRemarks() {
		return this.remarks;
	}
}
